<template>
  <div class="container">
    <baleTable :tableData="tableData" :tableHead="tableHead" :isSearch="true" :tableLoading="tableLoading" :page="page"
      @pageSizeChange="pageSizeChange" @handleCurrentChange="handleCurrentChange" @searchMethods="searchMethods"
      @tableSortChange="tableSortChange" @handleRowClick="handleRowClick" ref="baleTable">
      <template #headLeft>
        <!--    <el-button size="small" type="success" @click="importData()">数据导入</el-button> -->
        <el-button size="small" type="primary" @click="showDialog('')">添加</el-button>
        <!-- <div
          class="ml10 tableStats-btn tableStats-btn-active"
          @click="showDialog('')"
        >
          添加
        </div> -->
      </template>
      <template #team_icon="{ scope }">
        <div @click.stop="">
          <tablePrImg v-if="scope.row.team_icon" :imgSrc="scope.row.team_icon" :prImgList="[scope.row.team_icon]" />
        </div>
      </template>

      <!-- 机构名称 -->
      <!--    <template #open="{ scope }">
        {{formatterOpenArr(scope.row.open)}}
      </template> -->

      <template #open="{ scope }">
        <p @click.stop="">
          <el-switch :value="scope.row.open" :active-value="1" :inactive-value="0" active-text="接诊" inactive-text="不接诊"
            @change="(val)=>handleDownSwitch(scope.row.open,scope.row.id)">
          </el-switch>
        </p>

      </template>

      <!--    操作 -->
      <template #tableOperation="{ scope }">
        <el-button type="primary" size="small" @click="showTeamDoctor(scope.row)">查看团队医生</el-button>
        <el-button type="primary" size="small" @click="showDialog(scope.row)">编 辑</el-button>
        <el-button type="danger" size="small" @click="deList(scope.row.id)">删除</el-button>
      </template>
    </baleTable>
    <basicDialog ref="basicDialog" @refresh="getTableData()" />
    <teamDoctor ref="teamDoctor" @refresh="getTableData()" />
    <!--   <userList ref="userListDialog"></userList> -->
  </div>
</template>

<script>

import {
  ApiGetDoctorTeamList,
  ApiDelDoctorTeam,
  ApiUpdateTeamStatus
} from "@a/index";
import basicDialog from "./component/basicDialog.vue";
import { tableHead } from "./config";
import tablePrImg from "@/components/tablePrImg.vue";
import teamDoctor from "./component/teamDoctor.vue"
//获取用户列表数据
/* import userList from "./component/userList.vue"; */
export default {

  components: {
    tablePrImg,
    basicDialog,
    teamDoctor
    /*   userList, */
  },
  data() {
    return {
      tableHead,
      tableData: [],
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      tableLoading: false,
      searchParams: {},
      sortParams: {},
      editFormVisible: false,
      btnLoading: false,
      unitList: [],
      subDepartMentArr: [],
      openArr: [
        { name: "接诊", code: "1" },
        { name: "不接诊", code: "0" },
      ],
    };
  },
  mounted() {
    this.getTableData();
  },

  methods: {

    handleDownSwitch(val, id) {
      let status = (val == 1) ? 0 : 1
      this.$confirm(
        `确认修改该状态嘛？`,
        "提示",
        {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          dangerouslyUseHTMLString: true,
          center: true,
        }
      )
        .then(() => {
          ApiUpdateTeamStatus(id, { status }).then(_ => {
            this.$message.success("修改成功");
            this.getTableData()
          })
        })
        .catch(() => { });
    },



    showTeamDoctor(row) {
      this.$refs.teamDoctor.show(row)
    },


    formatterOpenArr(val) {
      let data = this.openArr.find(item => {
        if (item.code == val) {
          return item
        }
      })

      if (data) {
        return data.name
      } else {
        return val
      }
    },





    importData() {
      this.$refs.importData.show();
    },


    //编辑界面
    onEdit() { },
    showDialog(val) {
      this.$refs.basicDialog.show(val);
    },
    /*    userList(id) {
      this.$router.push({
        name: "detail",
        params: { id },
      });
    }, */
    getTableData(params = {}) {
      let postParams = {
        ...params,
        ...this.searchParams,
        ...this.sortParams,
        ...this.page,
      };
      this.tableLoading = true;
      ApiGetDoctorTeamList(postParams).then((res) => {
        let { data, page } = res;
        this.tableData = data;
        this.page.total = page.total;
        this.tableLoading = false;
      });
    },
    searchMethods(params) {
      this.searchParams = {};
      this.page.page = 1;
      this.searchParams = params;
      this.getTableData();
    },
    pageSizeChange(val) {
      this.page.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTableData();
    },
    tableSortChange(params) {
      if (params.sort_str) {
        this.sortParams = { ...this.sortParams, ...params };
      } else {
        delete this.sortParams.sort_str;
        delete this.sortParams.sort_order;
      }
      this.page.page = 1;
      this.getTableData();
    },

    handleRowClick(params) { },
    //shanchu
    deList(id) {
      this.$confirm("是否删除该数据项?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          ApiDelDoctorTeam(id).then((res) => {
            this.$message.success("操作成功！");
            this.getTableData();
          });
        })
        .catch((err) => { });
    },

    /*    resetButton(id) {
         this.$confirm("是否确认重置密码?", "提示", {
           confirmButtonText: "确定",
           cancelButtonText: "取消",
           center: true,
           type: "warning",
         })
           .then((res) => {
             ApiResetPassword(id).then((res) => {
               this.$alert("重置成功，该员工初始密码为：123456", "提示", {
                 confirmButtonText: "确定",
                 callback: (action) => { },
               });
               this.getTableData();
             });
           })
           .catch((err) => { });
       }, */

  },
  filters: {},
};
</script>

<style lang="less" scoped></style>
